<?php
if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Profile extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->library('parser');
		$this->load->model('m_profil');
	}

	function index(){
		show_404();
	}

	function detail_profile(){
		$this->load->helper('options');

		//ambil data uri
		$slug2							=	$this->uri->segment('2');

		if(!empty($slug2) && $this->cek_slug($slug2)){
			//ambil berita
			$data['results'] 	= $this->m_profil->get_by_slug($slug2);

			//potong kalimat per kata dan hilangkan tag html
			$this->load->helper('trim_text');
			//set title and meta description
			$this->parser->set_title($data['results']['judul']);
			$this->parser->set_desc(trim_text($data['results']['konten'],140));

			$this->parser->theme('front','profile/index', $data);

		}elseif(!empty($slug2) && $this->cek_slug_ahli($slug2)){
			//ambil berita
			$data['results'] 	= $this->m_profil->get_ahli_by_slug($slug2);

			//potong kalimat per kata dan hilangkan tag html
			$this->load->helper('trim_text');
			//set title and meta description
			$this->parser->set_title($data['results']['nama']);
			$this->parser->set_desc(trim_text($data['results']['konten'],140));

			$this->parser->theme('front','profile/detail_ahli', $data);
		}else{
			show_404();
		}
	}

	/*function detail_ahli(){
		$this->load->helper('options');

		//ambil data uri
		$slug2							=	$this->uri->segment('2');

		if(!empty($slug2) && $this->cek_slug_ahli($slug2)){
			//ambil berita
			$data['results'] 	= $this->m_profil->get_ahli_by_slug($slug2);

			//potong kalimat per kata dan hilangkan tag html
			$this->load->helper('trim_text');
			//set title and meta description
			$this->parser->set_title($data['results']['nama']);
			$this->parser->set_desc(trim_text($data['results']['konten'],140));

			$this->parser->theme('front','profile/detail_ahli', $data);

		}else{
			show_404();
		}
	}*/

	//private
	//bool
	private function cek_slug($slug){
		if (empty($slug))
		{
			return FALSE;
		}

		return $this->db->where('slug', $slug)
				->order_by("id_profil", "ASC")
				->limit(1)
		    ->count_all_results('profil') > 0;
	}

	private function cek_slug_ahli($slug){
		if (empty($slug))
		{
			return FALSE;
		}

		return $this->db->where('slug', $slug)
				->order_by("id_tenaga", "ASC")
				->limit(1)
		    ->count_all_results('tenaga_ahli') > 0;
	}

	function tenaga_ahli(){
			$data['results'] 	= $this->m_profil->get_tenaga_ahli();

			//set title and meta description
			$this->parser->set_title('Tenaga Ahli Pilar Teknotama');
			$this->parser->set_desc('Profil para tenaga ahli Pilar Teknotama');

			$this->parser->theme('front','profile/tenaga_ahli', $data);
	}
}